import React, { Component } from "react";
import "./header.scss";
import { withRouter } from "react-router-dom";
import menuList from "../../config/menuConfig";
import { getUser } from "../../plugins/local";
import { removeToken } from "../../plugins/session";
import { Modal, Button } from "antd";
import { LogoutOutlined } from "@ant-design/icons";
// import { getWeather } from "../../api/getWeather";
const { confirm } = Modal;
class Header extends Component {
  constructor(props) {
    super(props);
    this.state = {};
  }
  logout = () => {
    confirm({
      title: "是否要退出?",
      onOk: () => {
        removeToken();
        this.props.history.replace("/");
      },
    });
  };
  getTitle = () => {
    let path = this.props.location.pathname;
    let title;
    menuList.forEach((element) => {
      if (element.key === path) {
        title = element.title;
      } else if (element.children) {
        let item = element.children.find((item) => item.key === path);
        if (item) {
          title = item.title;
        }
      }
    });
    return title;
  };
  render() {
    let title = this.getTitle();
    return (
      <div className="header-content">
        <div className="header-left">{title}</div>
        <div className="header-right">
          <div className="header-top">
            欢迎 <span>&nbsp;&nbsp;{getUser()}&nbsp;&nbsp;</span>
            <Button
              type="dashed"
              shape="circle"
              icon={<LogoutOutlined />}
              onClick={this.logout}
            />
          </div>
          <div className="header-footer">2020年6月23日00:07:54 晴</div>
        </div>
      </div>
    );
  }
}
export default withRouter(Header);
